package com.xomily.devops.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.xomily.common.core.controller.BaseController;
import com.xomily.common.core.domain.AjaxResult;
import com.xomily.common.utils.DateUtils;
import com.xomily.devops.service.IDevCpuLogService;

/**
 * 温度监测日志Controller
 * 
 * @author xomily
 * @date 2021-12-24
 */
@RestController
@RequestMapping("/devops/temperatureLog")
public class DevTemperatureLogController extends BaseController {
	@Autowired
	private IDevCpuLogService devCpuLogService;

	/**
	 * 查询温度监测日志图表分析
	 */
	@PreAuthorize("@ss.hasPermi('devops:temperatureLog:graph')")
	@GetMapping("/graph")
	public AjaxResult graph(@RequestParam(name = "id") long id, @RequestParam(name = "dt", required = false) Date dt) {
		Map<String, Object> params = new HashMap<String, Object>();

		if (id == 0) {
			return AjaxResult.error("Id is error!");
		}
		Date t = DateUtils.getNowDate();
		if (dt != null) {
			t = dt;
		}
		;

		String graphDate = DateUtils.dateTime(t);
		params.put("startTime", DateUtils.parseDate(graphDate + " 00:00:00"));
		params.put("endTime", DateUtils.parseDate(graphDate + " 23:59:59"));
		params.put("hostId", String.valueOf(id));
		Map<String, Object> result = devCpuLogService.selectDevTemperatureLogByGraph(params);
		return AjaxResult.success(result);
	}

}
